package com.sxyjhh.fg_data_push.utils.util;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;

import java.text.SimpleDateFormat;
import java.util.Collection;

/**
 * Created by Shaok Lei on 2017/4/11 0011.
 */
public class JsonDateChangeUtil {
    public static JSONObject objChange(Object obj){
        JsonConfig jsonConfig = new JsonConfig();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        jsonConfig.registerJsonValueProcessor(java.util.Date.class, new JsonDateValueProcessor(simpleDateFormat));
        return JSONObject.fromObject(obj,jsonConfig);
    }
    public static JSONArray collectionChange(Collection collection){
        JsonConfig jsonConfig = new JsonConfig();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        jsonConfig.registerJsonValueProcessor(java.util.Date.class, new JsonDateValueProcessor(simpleDateFormat));
        return JSONArray.fromObject(collection,jsonConfig);
    }
}
